<?php
/**
 * 分类信息
 */

define('IN_ECS', true);
require(dirname(__FILE__) . '/includes/init.php');

$cate = get_child_tree(145);
//var_dump($cate);
$i = 0;
while($i < count($cate))
{
	$cate[$i]['cateTree'] = get_child_tree($cate[$i]['id']);
    $i++;
}

$response = array('response' => 'categoryInfo', 'categoryInfo' => $cate);

 echo tourldecode($response);

/**
 * 获得分类子树
 * @param  integer $tree_id 当前分类ID
 * @return [type]           该分类下的子树
 */
function get_child_tree($tree_id = 145)
{
    $cate = array();
    $arr =  array();
    $sql = 'SELECT count(*) FROM ' . $GLOBALS['ecs']->table('category') . " WHERE parent_id = '$tree_id' AND is_show = 1 ";
    if ($GLOBALS['db']->getOne($sql) || $tree_id == 0)
    {
        $child_sql = 'SELECT cat_id, cat_name, parent_id, is_show ' .
                'FROM ' . $GLOBALS['ecs']->table('category') .
                "WHERE parent_id = '$tree_id' AND is_show = 1 ORDER BY sort_order ASC, cat_id ASC";
        $res = $GLOBALS['db']->getAll($child_sql);
        foreach ($res AS $row)
        {
            if ($row['is_show'])
			{
                $cate[$row['cat_id']]['id']   = $row['cat_id'];
                $cate[$row['cat_id']]['name'] = urlencode($row['cat_name']);
                $arr[] = $cate[$row['cat_id']];
            }
            
        }
        
    }
    return $arr;
}